<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<%@ include file="/base/jsp/include.jsp"%>
</head>
<body>
	<form id="form" method="post">
		<fieldset style="border:solid 1px #aaa;padding:10px;">
			<legend>消息推送</legend>
			<div style="padding:5px;">
				<table style="height:100%;width:100%;table-layout:fixed;">
					<tr>
						<td style="width:50px;">输入推送消息</td>
						<td style="width:200px;"><input name="msg" id="msg" class="mini-textarea" style="width:300px;height:100px;" required="true" vtype="maxLength:50" /></td>
					</tr>
				</table>
			</div>
		</fieldset>

		<div style="text-align:left;padding:10px 0px 0px 2px;">
			<a class="mini-button" onclick="onOk" style="width:100px;margin-right:20px;">推送全部</a>
			<a class="mini-button" onclick="onOkAndroid" style="width:100px;margin-right:20px;">推送安卓</a>
			<a class="mini-button" onclick="onOkIOS" style="width:100px;margin-right:20px;">推送IOS</a>
			<a class="mini-button" onclick="onReset" style="width:60px;">重置</a>
		</div>
		
	</form>
	<script type="text/javascript">	
	    mini.parse();
		var form = new mini.Form("#form");
		var id = '';
		var module = '';
		var device = '';

		function GetData() {
			var o = form.getData();
			return o;
		}	
		
		function onOk(e) {
			device = 'all';
			push();
		}
		
		function onOkAndroid(e) {
			device = 'android';
			push();
		}
		
		function onOkIOS(e) {
			device = 'ios';
			push();
		}
		
		function push(){
			form.validate();
			var msg = mini.get("msg").getValue();
			if(msg == ''){
				mini.alert("请输入推送内容");
				return ;
			}
			mini.confirm("确定推送吗？", "确定？", function(action) {
				var messageId = mini.loading("正在加载..","加载中");
    			if (action == "ok") {
        			$.ajax({
                    	url: "pushWebUrl.do?ids=" + id + "&module=" + module + "&device=" + device + "&msg=" + msg,
                    	type: 'get',
                    	cache: false,
                    	success: function (text) {
                    		mini.hideMessageBox(messageId);
                    		if(text.indexOf("length") > -1){
                    			mini.alert("字符太长");
                    		}else{
                    			mini.alert("推送成功");
                    		}
                   			//grid.reload();
                   			//mini.get("msg").setValue("");
                    	},
                    	error: function (jqXHR, textStatus, errorThrown) {
                    		mini.hideMessageBox(messageId);
                    	    alert(jqXHR.responseText);
                    	}
            		});
    			}
    		});
		}
		
		 //标准方法接口定义
        function SetData(data) {
            if (data.action == "pushJ") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
                id = data.id;
                module = data.module;
                device = data.device;
            }
        }
        
		function onReset(e) {
			mini.get("msg").setValue("");
		}
	</script>
</body>
</html>
